﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProgNetAppBlocks.Forms;

namespace MiniKsiegowosc.Ustawienia.VatS
{
    public partial class FormVatS : ProgNetSpreadSheetForm
    {
        public FormVatS()
        {
            InitializeComponent();
        }

        protected override void FinishEdit()
        {
            base.FinishEdit();
            DataRow[] rows = vatSDataSet1.STP_VATS.Select();
            foreach (DataRow r in rows)
                r.SetColumnValue("STP_VATS_NAZWA", r["STP_VATS_NAZWA"].AsString().Trim());
        }
        
        protected override bool ValidateRow(DataRow r, DevExpress.XtraGrid.Views.Grid.GridView gv)
        {
            bool result = base.ValidateRow(r, gv);
            if (gv == gvMain)
            {
                if (!r.IsColumnUnique("STP_VATS_NAZWA"))
                {
                    r.SetColumnError("STP_VATS_NAZWA", "Nazwa powinna być unikalna");
                    AddError("Nazwa powinna być unikalna");
                    result = false;
                }
            }
            return result;
        }
    }
}
